package com.hfi.ood.litejunit.v3.framework.manipulation;

import com.hfi.ood.litejunit.v3.framework.runner.Description;
import com.hfi.ood.litejunit.v3.framework.runner.Runner;

import java.util.Comparator;

/**
 * @author ChangLiang
 * @date 2020/5/28
 */
public class Sorter implements Comparator<Description> {
    private final Comparator<Description> fComparator;

    public Sorter(Comparator<Description> comparator) {
        fComparator= comparator;
    }

    public void apply(Runner runner) {
        if (runner instanceof Sortable) {
            Sortable sortable= (Sortable) runner;
            sortable.sort(this);
        }
    }

    @Override
    public int compare(Description o1, Description o2) {
        return fComparator.compare(o1, o2);
    }
}
